let vm = new Vue({
    el: ".warehouse2",
    data: {
        loading: false,
        tableData: [],
        tfootContent: {},
        test: [],
        allpages: 0
    },
    methods: {
        getDate() {
            this.loading = true;
            let par = {
                code: leiku.GetUrlParam("code"),
                name: leiku.GetUrlParam("name"),
                pg: leiku.GetUrlParam("pg"),
                cangku: leiku.GetUrlParam("cangku"),
                khid: leiku.GetUrlParam("khid "),
                cangwei: leiku.GetUrlParam("cangwei"),
                benwaicangku: leiku.GetUrlParam("benwaicangku"),
                neibupici: leiku.GetUrlParam("neibupici"),
            }

            leiku.post('http://dongtai.fsslpc.com/api/2020092398760771', par, res => {
                let data = res.data;
                console.log(data)
                if (data.a.length) {
                    this.tableData = data;
                    this.tfootContent = data.b[0];

                    this.printPageing();
                    $(".count").text($(".container").find("table").length);
                    this.loading = false;
                }
                // console.log(data.a.length)
            })
        },
        printPageing() {
            const printHeight = 980;
            this.tableData.a.forEach(item => {
                $("#CS").html(`
                    <tr class="tdStyle" style="font-size:12px">
                        <td class="max-w">${item.name || ''}</td>
                        <td style="">${item.code || ''}</td>
                        <td style="">${item.jianxie || ''}</td>
                        <td style="">${item.bm || ''}</td>
                        <td style="">${item.cktx || ''}</td>
                        <td style="">${item.cwtx || ''}</td>
                        <td style="">${item.neibupici || ''}</td>
                        <td style="">${item.pg || ''}</td>
                        <td style="">${item.xckg || ''}</td>
                        <td style="">${item.xcjianshu || ''}</td>
                        <td style="">${item.remarks || ''}</td>                            
                    </tr>
                `)
                let csendTr = $("#CS").outerHeight();
                let tbLen = $(".container").find("table").length - 1;
                let currentTable = $(".container").find("table").eq(tbLen);
                let Num = 297;

               /*  if (leiku.getChromeVersion() <= 49) {
                    Num = 297;

                } else {
                    Num = 297;

                } */
                let tbH = currentTable.outerHeight(true);
                let countH = parseInt(new leiku.unitConversion().mmConversionPx(Num));
                /* console.log(currentTable.outerHeight(true), countH, csendTr) */
                /*  console.log('第' + tbLen + '个', currentTable.outerHeight(true), parseInt(new leiku.unitConversion().mmConversionPx(Num)), parseInt(countH - tbH) > chazhi) */
                if (tbH < countH && (parseInt(countH - tbH) > csendTr + 22)) {

                    currentTable.find("tbody").append(
                        `
                        <tr class="tdStyle">
                            <td class="max-w" style="">${item.name || ''}</td>
                            <td style="">${item.code || ''}</td>
                            <td style="">${item.jianxie || ''}</td>
                            <td style="">${item.bm || ''}</td>
                            <td style="">${item.cktx || ''}</td>
                            <td style="">${item.cwtx || ''}</td>
                            <td style="">${item.neibupici || ''}</td>
                            <td style="">${item.pg || ''}</td>
                            <td style="">${item.xckg || ''}</td>
                            <td style="">${item.xcjianshu || ''}</td>
                            <td style="">${item.remarks || ''}</td>                            
                        </tr>
                    `)
                } else {
                    $("#CS").html('')
                    let str =
                        `<div class="cut"></div>
                        <table style="width:100%" >
                            <thead class="header">
                                <tr>
                                    <th colspan="12"  style="font-size: 20px;padding-top:0px;position: relative;border-color: transparent;border-bottom-color: black;">
                                        <span>仓库资料查询报表: 二次料仓库</span>
                                        <span style="position: absolute; right:20px;bottom:0px; font-size: 15px;">
                                        <span class="page">第${tbLen + 2}页，</span>
                                        共<span class="count"></span>页                                                   
                                        </span>
                                    </th>
                                </tr>
                                <tr class="thStyle">
                                <th style="width: 22mm;">名称</th>
                                <th style="width:  19mm;">产品编码</th>
                                <th style="width:  19mm;">供应商</th>
                                <th style="width:  17mm;">部门</th>
                                <th style="width: 17mm;">仓库</th>
                                <th style="width:  17mm;">仓位</th>
                                <th style="width:  19mm;">内部批次</th>
                                <th style="width:  19mm;">加工厂批次</th>
                                <th style="width:  19mm;">现存数量(KG)</th>
                                <th style="width:  19mm;">现存件数</th>
                                <th class="bz" style="width:  22mm;">备注</th>
                                </tr>
                            </thead>
        
                            <tbody>
                            </tbody>
                                            
                            <tfoot class="tfStyle">
                                <td style="">总数量：</td>
                                <td style="">${this.tfootContent.sumxckg}</td>
                                <td style="">总件数：</td>
                                <td style="">${this.tfootContent.sumxcjianshu}</td>
                                <td style="" colspan="2">制表人：</td>
                                <td style="" colspan="2">${this.tfootContent.printer}</td>
                                <td style="" colspan="2">制表日期：</td>
                                <td style="" class="bz">${this.tfootContent.printtime}</td>
                            </tfoot>
                        </table>
                    `;
                    $(".container").append(str);
                }

            })
            /* $('.cut').first().remove() */
        },
        prints() {
            $(this.$refs.printPage).print({
                //stylesheet: "../css/warehouse_info5.css",
                globalStyles: true,
                mediaPrint: true,
                iframe: true,
            });
        }
    },
    computed: {
       
    },
    mounted() {
        this.getDate();
    }
})